package com.example.day_0813_103.slice;

import com.example.day_0813_103.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.render.render3d.TargetBuffer;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.lang.annotation.Target;
import java.util.HashSet;
import java.util.Set;

public class Three_AbilitySlice extends AbilitySlice {
    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP,0x00201,"MY_TAG");

    @Override
    public void onStart(Intent intent) {
        HiLog.info(LABEL,"这里是 Three_AbilitySlice 的 onStart");
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_three_);
//        findComponentById(ResourceTable.Id_main_id)
//                .setClickedListener(component -> present(new MainAbilitySlice(),));
        Text text = (Text) findComponentById(ResourceTable.Id_three_t_two);
        text.setText(intent.getStringParam("selut"));

        Set<String> set = intent.getEntities();
        for (String value: set){
            HiLog.info(LABEL,value);
        }

        findComponentById(ResourceTable.Id_Three_btn)
                .setClickedListener(component -> myablity("com.example.day_0813_103.four_Ability"));

    }
    public void myablity(String component) {
        Intent it = new Intent();
        Set<String> set = new HashSet<>();
        set.add("给自己打气");
        set.add("加油");
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.day_0813_103")
                .withAbilityName(component)
                .withEntities(set)
                .build();
        it.setOperation(operation);
        it.setParam("value","你最强！");
        startAbilityForResult(it,456);
    }
    @Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {
        super.onAbilityResult(requestCode, resultCode, resultData);
        HiLog.info(LABEL,"这里是 Three_AbilitySlice 的 onAbilityResult");
        HiLog.info(LABEL,String.valueOf(requestCode));
        HiLog.info(LABEL,String.valueOf(resultCode));
        HiLog.info(LABEL,resultData.getStringParam("value"));
    }

    @Override
    public void onActive() {
        HiLog.info(LABEL,"这里是 Three_AbilitySlice 的 onActive");
        super.onActive();
    }
    @Override
    protected void onInactive() {
        HiLog.info(LABEL,"这里是 Three_AbilitySlice 的 onInactive");
        super.onInactive();
    }

    @Override
    protected void onBackground() {
        HiLog.info(LABEL,"这里是 Three_AbilitySlice 的 onBackground");
        super.onBackground();
    }
    @Override
    public void onForeground(Intent intent) {
        HiLog.info(LABEL,"这里是 Three_AbilitySlice 的 onForeground");
        super.onForeground(intent);
    }
    @Override
    protected void onStop() {
        HiLog.info(LABEL,"这里是 Three_AbilitySlice 的 onStop");
        super.onStop();
    }
}
